package com.forever7776.life.core.service.impl.blog;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.forever7776.life.core.common.util.ResultVoUtil;
import com.forever7776.life.core.entity.blog.BlogType;
import com.forever7776.life.core.entity.sys.SysFunction;
import com.forever7776.life.core.mapper.blog.BlogTypeMapper;
import com.forever7776.life.core.service.blog.IBlogTypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.forever7776.life.remote.common.vo.ResultVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 博客类型表 服务实现类
 * </p>
 *
 * @author kz
 * @since 2018-02-11
 */
@Service
public class BlogTypeServiceImpl extends ServiceImpl<BlogTypeMapper, BlogType> implements IBlogTypeService {


    @Override
    public List<BlogType> selectAll(Integer status) {
        EntityWrapper<BlogType> ew = new EntityWrapper<BlogType>();
        if (status != null) {
            ew.eq("status", status);
        }
        return selectList(ew);
    }

    @Override
    public ResultVO frozen(String id, Integer status) {
        BlogType blogType = selectById(id);
        if (blogType == null) {
            return ResultVoUtil.getFailResult("该博客类型不存在！");
        }
        blogType.setStatus(status);
        this.updateById(blogType);
        return ResultVoUtil.getSuccessResult("操作成功！");
    }

    /**
     * 构造博客类型map形式，id-name
     *
     * @param list
     * @return
     */
    @Override
    public Map<String, String> createBlogTypeMap(List<BlogType> list) {
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        Map<String, String> map = new HashMap<>(list.size());
        for (BlogType item : list) {
            map.put(item.getId(), item.getName());
        }
        return map;
    }

}
